/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package net.worlds.ui.edge;

import java.awt.Color;
import java.awt.image.BufferedImage;


public class EToolbar extends EStickyFrame{
    int cx;
    int buttonSpacing;
    int buttonWidth;
    int padding;
    Color bgColor;
    Color buttonColor;
    Color separatorColor;
    EButtonGroup currentButtonGroup = null;
    public EToolbar(int height, int y, int buttonWidth, int padding, int buttonSpacing)
    {
        super(null, -1, height, 0, 0, y, 0);
        this.padding = padding;
        cx = buttonSpacing;
        this.buttonSpacing = buttonSpacing;
        this.buttonWidth = buttonWidth;
        setUndecorated(true);
    }
    public void setButtonGroup(EButtonGroup bg)
    {
        currentButtonGroup = bg;
    }
    public void setColors(Color bg, Color button, Color separator)
    {
        bgColor = bg;
        buttonColor = button;
        separatorColor = separator;
        setBackgroundColor(bgColor);
    }
    public EButton addButton(String text)
    {
        EButton b = new EButton(text);
        b.setX(cx);
        b.setWidth(buttonWidth);
        b.setHeight(buttonWidth);
        b.setY(padding);
        b.setColor(buttonColor);
        b.setHeight(getHeight() - padding * 2);
        addChild(1, b);
        cx += buttonSpacing + buttonWidth;
        return b;
    }
    public void addSeparator()
    {
        cx += buttonSpacing;
        ESeparator s = new ESeparator(cx, padding, getHeight() - padding * 2);
        s.setColor(separatorColor);
        addChild(1, s);
        cx += buttonSpacing * 2 + 1;
    }
    public EButton addButton(BufferedImage image)
    {
        EButton b = new EButton(image);
        b.setX(cx);
        b.setWidth(buttonWidth);
        b.setHeight(buttonWidth);
        b.setY(padding);
        b.setColor(buttonColor);
        b.setHeight(getHeight() - padding * 2);
        addChild(1, b);
        cx += buttonSpacing + buttonWidth;
        return b;
    }
    public EToggleButton addToggleButton(BufferedImage image)
    {
        EToggleButton b = new EToggleButton(image);
        if(currentButtonGroup != null)
            b.setButtonGroup(currentButtonGroup);
        b.setX(cx);
        b.setWidth(buttonWidth);
        b.setHeight(buttonWidth);
        b.setY(padding);
        b.setColor(buttonColor);
        b.setHeight(getHeight() - padding * 2);
        addChild(1, b);
        cx += buttonSpacing + buttonWidth;
        return b;
    }
}
